package me.cxlr.qinlauncher2.manager;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;

import com.orhanobut.logger.Logger;

import java.lang.reflect.Method;

import me.cxlr.qinlauncher2.view.DrawerActivity;
import me.cxlr.qinlauncher2.view.SettingsActivity;
import me.cxlr.qinlauncher2.view.launcher.AdjusVolume;
import me.cxlr.qinlauncher2.view.launcher.FlashLight;

/**
 * 动作管理
 *
 * @author 酷安用户:山轮纸
 */
public class ActionManager {
    private volatile static ActionManager actionManager;

    private ActionManager() {
    }

    public static ActionManager getInstance() {
        if (actionManager == null) {
            synchronized (ActionManager.class) {
                if (actionManager == null) {
                    actionManager = new ActionManager();
                }
            }
        }
        return actionManager;
    }

    public void openAction(FragmentActivity activity, Context context, String actionName) {
        Intent intent;
        ActivityOptionsCompat activityOptions;
        switch (actionName) {
            case "no":
                break;
            case "open short line":
                break;
            case "open app drawer":
                intent = new Intent(context, DrawerActivity.class);
                activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(activity);
                ActivityCompat.startActivity(context, intent, activityOptions.toBundle());
                break;
            case "open volume":
                AdjusVolume.getInstance().openVolume(activity);
                break;
            case "open flashlight":
                FlashLight.getInstance().useFlashLight();
                break;
            case "open launcher settings":
                intent = new Intent(context, SettingsActivity.class);
                activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(activity);
                ActivityCompat.startActivity(context, intent, activityOptions.toBundle());
                break;
            case "open notification":
                try {
                    @SuppressLint("WrongConstant") Object service = context.getSystemService("statusbar");
                    Method expand = service.getClass().getMethod("expandNotificationsPanel");
                    expand.invoke(service);
                } catch (Exception e) {
                    Logger.e("开启通知栏异常:" + e.toString());
                }
                break;
            default:
                break;
        }
    }
}
